var prefix = ctx + "manage/userDailyActivity";
var prefixAntiCheatDetail = ctx + "manage/antiCheatDetail";

$(function () {
    var options = {
        url: prefix + "/list",
        queryParams: queryParams,
        columns: [
            {
                checkbox: true
            },
            {
                field: 'usId',
                title: '用户id'
            },
            {
                field: 'usNickname',
                title: '用户名'
            },

            {
                field: 'udaSeparation',
                title: '分身',
                formatter: function (value, row, index) {
                    if (value === 2) {
                        return '<span class="badge badge-primary">否</span>';
                    }
                    if (value === 1) {
                        return '<span class="badge badge-danger">是</span>';
                    }
                }
            },
            {
                field: 'udaSimulator',
                title: '模拟器',
                formatter: function (value, row, index) {
                    if (value === 2) {
                        return '<span class="badge badge-primary">否</span>';
                    }
                    if (value === 1) {
                        return '<span class="badge badge-danger">是</span>';
                    }
                }
            },
            {
                field: 'udaDebugMode',
                title: '开启调试模式',
                formatter: function (value, row, index) {
                    if (value === 2) {
                        return '<span class="badge badge-primary">否</span>';
                    }
                    if (value === 1) {
                        return '<span class="badge badge-danger">是</span>';
                    }
                }
            },
            {
                field: 'udaUsbMode',
                title: 'USB调试模式',
                formatter: function (value, row, index) {
                    if (value === 2) {
                        return '<span class="badge badge-primary">否</span>';
                    }
                    if (value === 1) {
                        return '<span class="badge badge-danger">是</span>';
                    }
                }
            },
            {
                field: 'udaRoot',
                title: 'ROOT',
                formatter: function (value, row, index) {
                    if (value === 2) {
                        return '<span class="badge badge-primary">否</span>';
                    }
                    if (value === 1) {
                        return '<span class="badge badge-danger">是</span>';
                    }
                }
            },
            {
                field: 'udaAccessibility',
                title: '无障碍模式',
                formatter: function (value, row, index) {
                    if (value === 2) {
                        return '<span class="badge badge-primary">否</span>';
                    }
                    if (value === 1) {
                        return '<span class="badge badge-danger">是</span>';
                    }
                }
            },
            {
                field: 'udaVpnProxy',
                title: 'VPN代理',
                formatter: function (value, row, index) {
                    if (value === 2) {
                        return '<span class="badge badge-primary">否</span>';
                    }
                    if (value === 1) {
                        return '<span class="badge badge-danger">是</span>';
                    }
                }
            },
            {
                field: 'udaAppName',
                title: 'App名称'
            },
            {
                field: 'udaPackage',
                title: '包名'
            },
            {
                field: 'udaVersionCode',
                title: '版本号'
            },
            {
                field: 'udaSimOperator',
                title: 'SIM运营商'
            },
            {
                field: 'udaSimStatus',
                title: 'SIM状态',
                formatter: function (value, row, index) {
                    if (value === "1") {
                        return '已插卡';
                    }
                    if (value === "2") {
                        return '未插卡';
                    }
                    if (value === "3") {
                        return "未知";
                    }
                }
            },
            {
                field: 'udaNetWork',
                title: '当前网络'
            },
            {
                field: 'udaMac',
                title: 'Mac地址'
            },
            {
                field: 'udaBrand',
                title: '手机品牌'
            },
            {
                field: 'udaSystemVersionCode',
                title: '手机型号&系统版本'
            },
            {
                field: 'udaAndroid',
                title: 'Android版本号'
            },
            {
                field: 'udaAllApp',
                title: '手机总应用',
                formatter: function (value, row, index) {
                    return '<a href="#" onclick="getAppDetail(\'' + row.id + '\')">' + value + '</a>';
                }
            },
            {
                field: 'createTime',
                title: '更新时间'
            },
            {
                title: '操作',
                align: 'center',
                formatter: function (value, row, index) {
                    var actions = [];
                    actions.push('<a class="btn btn-primary btn-sm ' + antiCheatDetailAdd + '" href="#" title="编辑" mce_href="#" onclick="updateStatus(\'' + row.usId + '\')"><i class="fa fa-edit"></i>封号</a> ');
                    return actions.join('');
                }
            }]
    };
    $.ryTable.init(options);
});

/*奖励记录-搜索*/
function search() {
    $('.bootstrap-table').bootstrapTable('refresh', queryParams);
}

function queryParams(params) {
    var createTime = $('#createTime').val();
    return {
        // 传递参数查询参数
        pageSize: params.limit,
        pageNum: params.offset / params.limit + 1,
        usId: $("#usId").val(),
        nickname: $("#usNickname").val(),
        udaSystemVersionCode: $("#udaSystemVersionCode").val(),
        udaSeparation: $("#udaSeparation option:selected").val(),
        udaSimulator: $("#udaSimulator option:selected").val(),
        udaDebugMode: $("#udaDebugMode option:selected").val(),
        udaUsbMode: $("#udaUsbMode option:selected").val(),
        udaRoot: $("#udaRoot option:selected").val(),
        udaSimStatus: $("#udaSimStatus option:selected").val(),
        udaAccessibility: $("#udaAccessibility option:selected").val(),
        udaVpnProxy: $("#udaVpnProxy option:selected").val(),
        startUdaAllApp: $("#startUdaAllApp").val(),
        endUdaAllApp: $("#endUdaAllApp").val(),
        startTime: createTime === '' ? '' : startCreatTime,
        endTime: createTime === '' ? '' : endTime
    };
}

function updateStatus(id) {
    var url = prefixAntiCheatDetail + "/add/" + id;
    layer_showAuto("新增封号记录", url);
}

function getAppDetail(id) {
    var url = prefix + "/id/" + id;
    layer_showAuto("手机应用明细", url);
}
